<?php

use yii\db\Migration;

/**
 * Handles the creation of table `complaints`.
 */
class m190214_083509_create_complaints_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable('complaints', [
            'id'            => $this->primaryKey(),
            'uid'           => $this->integer()->comment('用户id'),
            'type'          => $this->tinyInteger(3)->comment('类型'),
            'contact_name'  => $this->string()->comment('联系人姓名'),
            'contact_phone' => $this->string()->comment('联系人电话'),
            'content'       => $this->string()->comment('详细内容'),
            'created_at'    => $this->integer(),
            'updated_at'    => $this->integer(),
        ]);
        $this->createTable('complaints_img', [
            'id'           => $this->primaryKey(),
            'complaint_id' => $this->integer(),
            'image_id'     => $this->integer(),
        ]);

        $this->addForeignKey('fk_complaint_user_id', 'complaints', 'uid', 'user', 'id');
        $this->addForeignKey('fk_complaint_image_id', 'complaints_img', 'image_id', 'image', 'id');
        $this->addForeignKey('fk_complaint_cimage_id', 'complaints_img', 'complaint_id', 'complaints', 'id');
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropTable('complaints');
        $this->dropTable('complaints_img');
    }
}
